﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Gnosis.Alexandria.Model
{
    public class Artist
        : NamedHashedAbbreviatedBase, IArtist
    {
        private ICountry _country;
        private string _note = string.Empty;
        private DateTime _startDate = DateTime.MinValue;
        private DateTime _endDate = DateTime.MaxValue;

        public override string RecordName
        {
            get { return "Artist"; }
        }

        protected override void InitializeField(string fieldName, object value)
        {
            if (fieldName == "Country")
                _country = Repository.Get<ICountry>(Convert.ToInt64(value));
            else if (fieldName == "Note")
                _note = (string)value;
            else if (fieldName == "StartDate")
                _startDate = DateTime.Parse((string)value);
            else if (fieldName == "EndDate")
                _endDate = DateTime.Parse((string)value);
            else
                base.InitializeField(fieldName, value);
        }

        #region IArtist Members

        public ICountry Country
        {
            get { return _country; }
            set {
                if (_country != value)
                {
                    _country = value;
                    AddChange("Country", value);
                }
            }
        }

        public string Note
        {
            get { return _note; }
            set
            {
                if (_note != value)
                {
                    _note = value;
                    AddChange("Note", value);
                }
            }
        }

        public DateTime StartDate
        {
            get { return _startDate; }
            set
            {
                if (_startDate.Date != value.Date)
                {
                    _startDate = value;
                    AddChange("StartDate", value);
                }
            }
        }

        public DateTime EndDate
        {
            get { return _endDate; }
            set
            {
                if (_endDate.Date != value.Date)
                {
                    _endDate = value;
                    AddChange("EndDate", value);
                }
            }
        }

        #endregion
    }
}
